package com.huxiaoshou.exam.config.properties;

import jakarta.annotation.PostConstruct;
import lombok.Data;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

@Data
@Configuration
public class ThreadProperties {

    /**
     * 核心线程数，默认CPU核心数
     */
    private int corePoolSize = Runtime.getRuntime().availableProcessors();

    /**
     * 最大线程数，默认CPU核心数 * 2
     */
    private int maxPoolSize = Runtime.getRuntime().availableProcessors() * 2;

    /**
     * 队列容量，默认1024
     */
    private int queueCapacity = 1024;

    /**
     * 空闲线程存活时间(秒)，默认60
     */
    private int keepAliveTime = 60;

    @PostConstruct
    public void validate() {
        Assert.isTrue(corePoolSize > 0, "核心线程数必须大于0");
        Assert.isTrue(maxPoolSize >= corePoolSize, "最大线程数必须大于等于核心线程数");
        Assert.isTrue(queueCapacity > 0, "队列容量必须大于0");
        Assert.isTrue(keepAliveTime >= 0, "空闲时间不能为负数");
    }

}
